package com.qiyeji.real_estate.controller;

import com.qiyeji.real_estate.entity.customer;
import com.qiyeji.real_estate.entity.project;
import com.qiyeji.real_estate.service.CustomerService;
import com.qiyeji.real_estate.service.ProjectService;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.File;

@Repository
public class CreateFileController implements JavaDelegate {

    //在文件操作中，不用/或者\最好，推荐使用File.separator
    private final static String  fileDir="Download";

    private  final static String rootPath = System.getProperty("user.dir") + File.separator+fileDir+File.separator;

    @Autowired
    ProjectService projectService;

    @Autowired
    CustomerService customerService;

    @Override
    public void execute(DelegateExecution execution) throws Exception {
//        createDir(rootPath);
//        project project = projectService.queryProjectByPCode(execution.getBusinessKey());
//
//        customer customer = customerService.selectById(project.getCid());
//        String projectPath = rootPath + project.getPname() + "-" + customer.getCname() + "-" + customer.getPrimaryunit() + "-" + project.getBuildTime();
//        createDir(projectPath);
//        String path = projectPath + File.separator + "jpg";
//        createDir(path);
//        path = projectPath + File.separator + "小样";
//        createDir(path);
//        path = projectPath + File.separator + "资料";
//        createDir(path);
//        path = projectPath + File.separator + "后期文件";
//        createDir(path);
//        path = path + File.separator + "原始文件";
//        createDir(path);
//        path = projectPath + File.separator + "模型文件";
//        createDir(path);
//        path = path + File.separator + "原始模型";
//        createDir(path);
//        path = projectPath + File.separator + "模型文件" + File.separator + "最终模型";
//        createDir(path);
//        path = projectPath + File.separator + "渲染文件";
//        createDir(path);
//        path = path + File.separator + "原始渲染";
//        createDir(path);
//        path = projectPath + File.separator + "渲染文件" + File.separator + "最终渲染";
//        createDir(path);
        System.out.println("创建完成！");

    }

//    private void createDir(String fileName) {
//        File file = new File(fileName);
//        if (!file.isDirectory() && !file.exists()){
//            file.mkdirs();
//        }
//        else
//            System.out.println("该文件夹已存在！");
//    }

}
